<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //Object.assign()
    //将多个对象的属性和方法都合并到目标对象上面
    //格式是(目标对象,后面跟着多个或者一个原对象)
    let target = {} //目标对象
    let name1 = {
        name: "aaa",
        age: "1212"
    }
    let name2 = {
        sex: "男"
    }
    let name3 = {
        sex: "女"
    }
    Object.assign(target, name1, name2, name3) //后面的name睡在后面就用谁的值
    console.log(target);

    //Object.assign()
    //将多个对象的属性和方法都合并到目标对象上面
    //格式是(目标对象,后面跟着多个或者一个原对象)

    let tar = {} //目标对象
    let sa1 = {
        name: "阿亮",
        age: '777'
    }
    let sa2 = {
        sex: "男"
    }
    let sa3 = {
            sex: "女"
        }
        //对象里面有相同属性时,谁写在后面就用谁的
    Object.assign(tar, sa1, sa2, sa3)
    console.log(tar);

    //Object.assign()
    //将多个对象的属性和方法都合并到目标对象上面
    //格式是(目标对象,后面跟着多个或者一个原对象)

    let t = {} //目标对象
    let name1 = {
        name: '贼',
        age: '212'
    }
    let name2 = {
        sex: '男'
    }
    let name3 = {
            sex: '女'
        }
        //对象里面有相同属性时,写在后的对象会覆盖前面对象相同属性的属性值
    Object.assign(t, name1, name2, name3)
    console.log(t);
</script>

</html>